package kameleon.document2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author xavier
 */
public abstract class DocumentElement extends DocumentElementProperties implements Iterable {
    
    List<DocumentElement> elements ;

    public DocumentElement() {

    }

    public void add(DocumentElement de) {
        this.elements.add(de);
    }
    
    public void remove(DocumentElement de) {
        this.elements.remove(de);
    }
    
    public void visit(DocumentAnalyzer da) {
        try {
            Method method = da.getClass().getDeclaredMethod(
                                             DocumentAnalyzer.ANALYZER_METHOD, this.getClass());
            method.invoke(da, this) ;
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(DocumentElement.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            Logger.getLogger(DocumentElement.class.getName()).log(Level.SEVERE, null, ex);
            
        } catch (IllegalAccessException ex) {
            Logger.getLogger(DocumentElement.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            Logger.getLogger(DocumentElement.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(DocumentElement.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public Iterator iterator() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
